<?php
	/*
		Processo Financeiro de BO
			para pagamento de multiplas remessas

	*/
		#Defaults
		$PIDCODE = 16;
		$InvoiceFlag = 11;	#Status Code Pago 11
		$StatusChangeObservations = $_POST['Observations'];
		$ToPayIds = preg_split('/,/',$_POST['SelectedPayments']);
		$prcResult = 0;
		$CNT = count($ToPayIds);
		$MSG = '';
		if($ToPayIds[0]==''){die('<div style="text-align:center;width:300px" class="Confirm">Nada para pagar.</div>');}
		# DO PRC
		CONN('MYI');
		for($i=0;$i<$CNT;$i++) {
			/*
				ALTERACAO fazer loop na linha do query e depois correr todos como so com uma ligacao

			*/
		$GLOBALS['MYI']->multi_query("CALL do_invoicepayment({$ToPayIds[$i]},{$PIDCODE},{$InvoiceFlag},'{$StatusChangeObservations}',
			{$_SESSION[$SESSID]},'{$sysTime}', @PrcResponse); SELECT @PrcResponse");
			do {$GLOBALS['MYI']->next_result();
				if ($result = $GLOBALS['MYI']->store_result()) {
					while ($row = $result->fetch_row()) {
					$prcResult = $row[0];
					# Desactivado historioco de alteracao para este processo.
					#hs_invoicestatus($InvoiceID,$sysTime,$PIDCODE,$InvoiceFlag,$StatusChangeObservations,$sysTime);
					if($prcResult<1){ $MSG .= $row[0];}
					}
					$result->free();
				}
			} while ($GLOBALS['MYI']->more_results());
		}
		$GLOBALS['MYI']->close();
		## END PRC

		if($prcResult>0){
			echo '<div style="text-align:center;width:300px" class="Confirm">Concluido.</div>
					<script type="text/language">replaceUrl(\'rsAccountPayments\',\'Modules/FTK9D4D0/Lib/a08_rsAcountPayments.php\');</script>';
		} else {
			echo '<div style="text-align:center;width:300px" class="Error">Erro no pagamento.</div>';
		}